package me.heyclock.hl.recordwriter.robot;

import android.util.Log;

import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;

import me.heyclock.hl.recordwriter.activity.HistoryActivity;
import me.heyclock.hl.recordwriter.activity.LoginActivity;

/**
 * 判断命令状态 - 模拟状态机
 * 命令：1. 打招呼（”小萌同学“）
 * 2. 当前在哪个页面
 * 3. 关掉某个页面
 * 4. 跳转到某个页面
 */
public class StateMachine {
    public static enum RE_COMMAND_TYPE {
        UNKNOW, HELLO, WHERE, CLOSE, JUMP
    }

    ;

    public static void getCommand(String commandMsg, ReBackListenner reBackListenner) {
        String pinYingRestul = commandMsg;
        try {
            pinYingRestul = PinyinHelper.convertToPinyinString(commandMsg,
                    "", PinyinFormat.WITHOUT_TONE);
            Log.e("test", "PinyinHelper=" + PinyinHelper.convertToPinyinString(commandMsg,
                    "", PinyinFormat.WITHOUT_TONE));
        } catch (PinyinException e) {
            ///e.printStackTrace();
            pinYingRestul = commandMsg;
        }
        if (pinYingRestul.contains("xiaomeng") ||
                pinYingRestul.contains("xiao,meng") ||
                pinYingRestul.contains("xiao,meng,tong,xue") ||
                pinYingRestul.contains("xiaomengtongxue") ||
                pinYingRestul.contains("xiaomentongxue")) {
            reBackListenner.reply(RE_COMMAND_TYPE.HELLO, "嗯。我在，你说。", null);
        } else if (pinYingRestul.contains("wozainali") ||
                pinYingRestul.contains("zainali") ||
                pinYingRestul.contains("zaina")) {
            reBackListenner.reply(RE_COMMAND_TYPE.WHERE, ActivityStack.getCurActMessage(), null);
        } else if (pinYingRestul.contains("guanbi")||
                pinYingRestul.contains("guandiao")) {
            reBackListenner.reply(RE_COMMAND_TYPE.CLOSE, ActivityStack.getCurActMessage(),ActivityStack.getActivty());
        } else if (pinYingRestul.contains("daowode")||
                pinYingRestul.contains("dao,wo,de")) {
            reBackListenner.reply(RE_COMMAND_TYPE.JUMP, ActivityStack.getCurActMessage(), LoginActivity.class);
        } else if (pinYingRestul.contains("daolishi") ||
                pinYingRestul.contains("dao,li,shi")) {
            reBackListenner.reply(RE_COMMAND_TYPE.JUMP, ActivityStack.getCurActMessage(), HistoryActivity.class);
        } else {
            reBackListenner.reply(RE_COMMAND_TYPE.UNKNOW, "没听懂了，小萌还需要加强学习!", null);
        }
    }

    public interface ReBackListenner {
        void reply(RE_COMMAND_TYPE re_command_type, Object msg, Object activity);
    }
}
